package cn.hejiang.mamis.core.service.impl;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.hejiang.mamis.core.dto.SysMenuDTO;
import cn.hejiang.mamis.core.entity.SysMenu;
import cn.hejiang.mamis.core.mapper.SysMenuMapper;
import cn.hejiang.mamis.core.service.SysMenuService;

@Service
@CacheConfig(keyGenerator = "cacheKeyGenerator")
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
	@Cacheable(cacheNames = "SYS_MENU")
	public List<SysMenuDTO> getMenuList(String sysId) {
		return this.getBaseMapper().getMenuList(sysId);
	}

	@Cacheable(cacheNames = "SYS_USER_MENU")
	public List<SysMenu> getUserMenuList(String userId, String deptId, String sysId) {
		return this.getBaseMapper().getUserMenuList(userId, deptId, sysId);
	}

	@CacheEvict(cacheNames = { "SYS_MENU", "SYS_ROLE_MENU", "SYS_USER_MENU" }, allEntries = true)
	public boolean save(SysMenu entity) {
		return super.save(entity);
	}

	@CacheEvict(cacheNames = { "SYS_MENU", "SYS_ROLE_MENU", "SYS_USER_MENU" }, allEntries = true)
	public boolean update(SysMenu entity, Wrapper<SysMenu> updateWrapper) {
		return super.update(entity, updateWrapper);
	}
}
